﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using umbraco.DataLayer;

namespace TestDataLayer
{
    [TestFixture]
    public class SqlParserTest
    {
        [Test]
        public void TestUpercaseIdentifiersWithEmptyString()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual(string.Empty, parser.UppercaseIdentifiers(string.Empty));
        }

        [Test]
        public void TestUpercaseIdentifiersWithNull()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual(string.Empty, parser.UppercaseIdentifiers(null));
        }

        [Test]
        public void TestUpercaseIdentifiersWithUppercaseQuery()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO;", parser.UppercaseIdentifiers("SELECT BAR FROM FOO;"));
        }

        [Test]
        public void TestUpercaseIdentifiersWithLowercaseQuery()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO;", parser.UppercaseIdentifiers("select bar from foo;"));
        }

        [Test]
        public void TestUpercaseIdentifiersWithMixedCaseQuery()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO;", parser.UppercaseIdentifiers("select BAR FROM foo;"));
        }

        [Test]
        public void TestUpercaseIdentifiersWithUppercaseQueryAndStrings()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO WHERE BOO='aBcDeF';",
                            parser.UppercaseIdentifiers("SELECT BAR FROM FOO WHERE BOO='aBcDeF';"));
        }

        [Test]
        public void TestUpercaseIdentifiersWithLowercaseQueryAndStrings()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO WHERE BOO='aBcDeF';",
                            parser.UppercaseIdentifiers("select bar from foo where boo='aBcDeF';"));
        }

        [Test]
        public void TestUpercaseIdentifiersWithMixedCaseQueryAndStrings()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO WHERE BOO='aBcDeF';",
                            parser.UppercaseIdentifiers("select BAR FROM foo where BOO='aBcDeF';"));
        }

        [Test]
        public void TestUpercaseIdentifiersWithMixedCaseQueryAndMultipleStrings()
        {
            SqlParser parser = new SqlParser();
            Assert.AreEqual("SELECT BAR FROM FOO WHERE BOO='aBcDeF' OR BOO='xyZ';",
                            parser.UppercaseIdentifiers("select BAR FROM foo where BOO='aBcDeF' or boo='xyZ';"));
        }
    }
}
